import Vue from 'vue'
import VueRouter from "vue-router";

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const Home = () => import('../views/home/Home')
const Category = () => import('../views/category/Category')
const Cart = () => import('../views/cart/Cart')
const Profile = () => import('../views/profile/Profile')
const detail = () => import('../views/detail/Detail')

const routes = [
  {
    path: '/',
    redirect: "/home"
  },

  {
    name: '首页',
    path: "/home",
    component: Home
  },
  {
    name: '分类',
    path: "/category",
    component: Category
  },
  {
    name: '购物车',
    path: "/cart",
    component: Cart
  },
  {
    name: '我的',
    path: "/profile",
    component: Profile
  },
  {
    name: "详情",
    path: '/detail/:iid',
    component: detail
  }

]
const router = new VueRouter({
  routes,
  mode: "history"
})

router.beforeEach(((to, from, next) => {
  document.title = to.name
  next()
}))


export default router













